package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.LpsOrderCdjgService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.LpsOrderCdjgForm;
import com.youlai.boot.system.model.query.LpsOrderCdjgQuery;
import com.youlai.boot.system.model.vo.LpsOrderCdjgVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 触动机构前端控制层
 *
 * @author lwb
 * @since 2025-07-13 16:03
 */
@Tag(name = "触动机构接口")
@RestController
@RequestMapping("/api/v1/lpsOrderCdjgs")
@RequiredArgsConstructor
public class LpsOrderCdjgController  {

    private final LpsOrderCdjgService lpsOrderCdjgService;

    @Operation(summary = "触动机构分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderCdjg:query')")
    public PageResult<LpsOrderCdjgVO> getLpsOrderCdjgPage(LpsOrderCdjgQuery queryParams ) {
        IPage<LpsOrderCdjgVO> result = lpsOrderCdjgService.getLpsOrderCdjgPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增触动机构")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:lpsOrderCdjg:add')")
    public Result<Void> saveLpsOrderCdjg(@RequestBody @Valid LpsOrderCdjgForm formData ) {
        boolean result = lpsOrderCdjgService.saveLpsOrderCdjg(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取触动机构表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderCdjg:edit')")
    public Result<LpsOrderCdjgForm> getLpsOrderCdjgForm(
        @Parameter(description = "触动机构ID") @PathVariable Long id
    ) {
        LpsOrderCdjgForm formData = lpsOrderCdjgService.getLpsOrderCdjgFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改触动机构")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderCdjg:edit')")
    public Result<Void> updateLpsOrderCdjg(
            @Parameter(description = "触动机构ID") @PathVariable Long id,
            @RequestBody @Validated LpsOrderCdjgForm formData
    ) {
        boolean result = lpsOrderCdjgService.updateLpsOrderCdjg(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除触动机构")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderCdjg:delete')")
    public Result<Void> deleteLpsOrderCdjgs(
        @Parameter(description = "触动机构ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = lpsOrderCdjgService.deleteLpsOrderCdjgs(ids);
        return Result.judge(result);
    }
}
